//
//  DownloadCollectionViewCell.m
//  CoolFM
//
//  Created by 曹曹 on 16/9/7.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "DownloadCollectionViewCell.h"
#import "DownloadHeaderView.h"

@interface DownloadCollectionViewCell () <UITableViewDelegate, UITableViewDataSource>
// tableView
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation DownloadCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    _tableView.delegate = self;
    _tableView.dataSource =self;
    _tableView.tableFooterView = [UIView new];
}
#pragma mark - tableView 代理
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuse = @"CELL";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
    }
    if (indexPath.section == 0) {
        cell.textLabel.text = @"暂无节目正在下载";
        cell.textLabel.font = [UIFont systemFontOfSize:13];
        cell.textLabel.textColor = [UIColor lightGrayColor];
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
    } else {
        cell.textLabel.text = @"暂无下载的节目";
        cell.textLabel.font = [UIFont systemFontOfSize:13];
        cell.textLabel.textColor = [UIColor lightGrayColor];
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
    }
    return  cell;
}
#pragma mark - 头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *header0 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.contentView.bounds), 30)];
    header0.backgroundColor = [UIColor grayColor];
    UIView *header1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.contentView.bounds), 30)];
    header1.backgroundColor = [UIColor grayColor];
    CGFloat headerW = CGRectGetWidth(self.bounds);
    DownloadHeaderView *firstHeaderView = [DownloadHeaderView downloadHeaderViewFrame:CGRectMake(0, 0, headerW, 30)
                                                                               Target:self
                                                                        leftBtnAction:@selector(topLeftButtonClicked:)
                                                                       rightBtnAction:@selector(topRigtButtonClicked:)
                                                                        controlsBlock:^(UILabel * _Nonnull titleLabel, UIButton * _Nonnull left, UIButton * _Nonnull right) {
        titleLabel.text = @"正在下载";
        titleLabel.font = [UIFont systemFontOfSize:12];
        titleLabel.textColor = [UIColor grayColor];
        [left setImage:[UIImage imageNamed:@"btn_more"] forState:UIControlStateNormal];
        [right setImage:[UIImage imageNamed:@"btn_more"] forState:UIControlStateNormal];
    }];
    firstHeaderView.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.00];
    DownloadHeaderView *secondHeaderView = [DownloadHeaderView downloadHeaderViewFrame:CGRectMake(0, 0, headerW, 30)
                                                                                Target:self
                                                                         leftBtnAction:@selector(bottomLeftClicked:)
                                                                        rightBtnAction:@selector(bottomRigtClicked:)
                                                                         controlsBlock:^(UILabel * _Nonnull titleLabel, UIButton * _Nonnull left, UIButton * _Nonnull right) {
        titleLabel.text = @"已下载";
        titleLabel.font = [UIFont systemFontOfSize:12];
        titleLabel.textColor = [UIColor grayColor];
        [left setImage:[UIImage imageNamed:@"btn_more"] forState:UIControlStateNormal];
        [right setImage:[UIImage imageNamed:@"btn_more"] forState:UIControlStateNormal];
    }];
    secondHeaderView.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.00];
    if (section == 0) {
        return firstHeaderView;
    } else {
        return secondHeaderView;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 30;
}
#pragma mark - 头视图Button点击事件
- (void)topLeftButtonClicked:(UIButton *)button {
    NSLog(@"select top left button");
}
- (void)topRigtButtonClicked:(UIButton *)button {
    NSLog(@"select top rigt button");
}
- (void)bottomLeftClicked:(UIButton *)button {
    NSLog(@"select bottom left button");
}
- (void)bottomRigtClicked:(UIButton *)button {
    NSLog(@"select bottom rigt button");
}

// 分区索引标题
//- (NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView {
//    NSArray *titleArray = @[@"downloading", @"downloaded"];
//    return titleArray;
//}

@end
